package com.atguigu.exam;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author xbd
 * @create 2021-05-25 21:52
 */
public class DistanceTest {
    public static void main(String[] args) {
        String date1 = "2010-09-20";
        String date2 = "2010-09-28";

        System.out.println(fun(date1, date2));
    }

    public static long fun(String time1,String time2){
        long dayDistance = 0;
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date1 = ft.parse(time1);
            Date date2 = ft.parse(time2);
            dayDistance = date2.getTime() - date1.getTime();
            dayDistance = dayDistance / 1000 / 60 / 60 / 24;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dayDistance;
    }
}
